package source;

import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

import java.util.ArrayList;

/**
 * Author itcast
 * Date 2021/6/16 9:40
 * Desc TODO
 */
public class FlinkSource {
    public static void main(String[] args) throws Exception {
        //1. 创建流环境
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
        //2. 从集合中读取数据
        env.setParallelism(1);
        //2.1 fromElement 从元素集合
        DataStreamSource<String> source = env.fromElements("hello world", "hello scala", "hello flink");
        //2.2 fromCollection  从集合列表
        ArrayList<String> strings = new ArrayList<>();
        strings.add("hello");
        strings.add("hello world");
        DataStreamSource<String> source1 = env.fromCollection(strings);
        //2.3 fromSequence   从序列
        DataStreamSource<Long> source2 = env.fromSequence(1, 10);
        //3. 打印输出
//        source.print();
//        source1.print();
        source2.print();
        //4. 运行执行
        env.execute();
    }
}
